package com.ssh.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.ssh.dao.UserDao;
import com.ssh.entity.User;

/**
 * DAO层 专做数据库增删改查操作
 * @author Administrator
 *
 */
@Repository
public class UserDaoImpl implements UserDao{
	
	@Autowired
	private HibernateTemplate ht;

	/**
	 * 执行HQL语句
	 */
	
	@SuppressWarnings("unchecked")
	@Override
	public User loadUserByName(String userName,String Password) {
		List<User> list = ht.find("from User where userName=? and password=?", userName,Password);
		if(null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void userRegister(User user) {
		ht.save(user);
	}

	@SuppressWarnings("unchecked")
	@Override
	public int selectUserName(String userName) {
		List<User> list = ht.find("from User where userName=?",userName);
		if(list.size() > 0 && list != null){
			return 1;
		}else{
			return 0;
		}
	}	
}
